package com.quasar.hpatient.view.adapter;

import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.PhotoModel;
import com.quasar.hpatient.model.litePalmodel.HospitalInfodb;
import com.quasar.hpatient.model.medicalmodel.CaseinformationData;
import com.quasar.hpatient.network.RetrofitConnection;
import com.quasar.hpatient.utils.Spanny;
import com.quasar.hpatient.widget.AutoHeightGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/12/13 0013
 * View:我的病例
 */

public class CaseAdapter extends BaseQuickAdapter<CaseinformationData, BaseViewHolder> {

    List<HospitalInfodb> hospitalInfodb= MainAppliaction.getInstance().getHospitalInfodbList();
    //将图片集合设置为static便于浏览界面调用
    public static ArrayList<String> photos = new ArrayList<>();

    public CaseAdapter() {
        super(R.layout.casel_item_ayout);
    }

    @Override
    protected void convert(BaseViewHolder helper, CaseinformationData item) {
        HospitalInfodb Infodb = null;

        //医院
        for (int i = 0; i < hospitalInfodb.size(); i++) {
            if (hospitalInfodb.get(i).getPrimaryid() == item.getHospitalId()) {
                Infodb = hospitalInfodb.get(i);
                break;
            }
        }

        //病例标题
        if (Infodb != null) {
            helper.setText(R.id.tv_hospital,Infodb.getName());
        }

        if (item.getTitle() != null) {
            helper.setText(R.id.tv_hospital_title,"(" + item.getTitle() + ")");
        }

        //时间
        if (item.getLogTime() != null) {
            helper.setText(R.id.tv_time, item.getMrdateTime().substring(0,10));
        }

        //内容
        if (item.getDescription() != null) {
            helper.setText(R.id.tv_cotent, item.getDescription());
        }

        AutoHeightGridView images = helper.getView(R.id.images);

        ImageAdapter adapter;

        ArrayList<PhotoModel> pms = new ArrayList<>();

        if (item.getPatientCaseHistoryDetail() != null) {

            String[] aa = item.getPatientCaseHistoryDetail().getCover().split(",");

            for (int i = 0; i < aa.length; i++) {
                pms.add(new PhotoModel(RetrofitConnection.PHOTOURL + aa[i]));
            }

            adapter = new ImageAdapter(mContext, pms);
            images.setAdapter(adapter);
            images.setOnItemClickListener(adapter);
        }
        helper.addOnClickListener(R.id.ll_case);
        helper.addOnLongClickListener(R.id.ll_case);
    }
}
